Completed
Push — master ( f991c2...b8dc7c )
by Andres
38s
created

angular.controller(ꞌmain-loopꞌ)   A

Complexity

Conditions 1
Paths 1

Size

Total Lines 3

Duplication

Lines 0
Ratio 0 %

Importance

Changes 0
Metric Value
cc 1
c 0
b 0
f 0
nc 1
dl 0
loc 3
rs 10
nop 0
1
'use strict';
2
3
angular
4
  .module('game')
5
  .controller('main-loop', ['$scope',
6
    '$interval',
7
    '$timeout',
8
    'savegame',
9
    'visibility',
10
    'state',
11
    function($scope, $interval, $timeout, savegame, visibility, state) {
12
      $scope.visibility = visibility;
13
      $scope.state = state;
14
15
      let self = this;
16
      let playerCopy = null;
17
18
      self.update = function() {
19
        // do the update in a copy
20
        playerCopy = angular.copy(state.player);
21
22
        state.update(playerCopy);
23
24
        // and update all at once
25
        state.player = playerCopy;
26
27
        $timeout(self.update, 1);
28
      };
29
30
      self.startup = function() {
31
        savegame.load();
32
        state.loading = false;
33
        $timeout(self.update, 1000);
34
        $interval(savegame.save, 10000);
35
      };
36
37
      $timeout(self.startup);
38
    }
39
  ]);
40